package com.mszlu.news.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mszlu.news.dao.mapper.ComplainMapper;
import com.mszlu.news.dao.pojo.Complain;
import com.mszlu.news.service.ComplainService;
import com.mszlu.news.vo.Result;
import com.mszlu.news.vo.params.ComplainParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ComplainServiceImpl implements ComplainService {
    @Autowired
    private ComplainMapper complainMapper;

    @Override
    public Result addComplain(ComplainParam complainParam) {
//        HashMap<String,Object> objectHashMap=new HashMap<>();
//        objectHashMap.put("article_id",complainParam.getArticleId());
//        objectHashMap.put("user_id",complainParam.getUserId());
//        complainMapper.selectByMap(objectHashMap);
        QueryWrapper<Complain> complainQueryWrapper=new QueryWrapper<>();
        complainQueryWrapper.eq("article_id",complainParam.getArticleId());
        complainQueryWrapper.eq("user_id",complainParam.getUserId());
        if(complainMapper.selectOne(complainQueryWrapper)!=null){
            return Result.success(null);
        }else {
            Complain complain = new Complain();
            complain.setArticleId(complainParam.getArticleId());
            complain.setAuthorId(complainParam.getAuthorId());
            complain.setUserId(complainParam.getUserId());
            complain.setComplainType(complainParam.getComplainType());
            complainMapper.insert(complain);
            return Result.success("举报成功");
        }
    }
}
